package com.tianqu.tms.www.transfer.action;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.User;
import com.tianqu.tms.www.transfer.viewhelper.TransferWorkCountViewHelper;

public class TransferWorkCountUpdateInputAction extends TmsAction {

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		TransferWorkCountViewHelper view = (TransferWorkCountViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		//从前台页面获取 岗位名称和姓名
		String workType = "";
		if(view.getWorkType()!=null&&!"".equals(view.getWorkType())) 
		{
			workType = view.getWorkType();
		}else{
			workType = new String(request.getParameter("workType").getBytes("ISO8859-1"), "UTF-8");
		}
		String userId = "";
		if(request.getParameter("userId")!=null)
		{
			userId = request.getParameter("userId");
		}else{
			userId = view.getUserid();
		}
		view.setWorkType(workType);
		view.setUserid(userId);
		User user = new User();
		user = user.getUserInfoById(Integer.parseInt(userId));
		view.setUserName(user.getRealName());
		view.setNowDate(DateUtil.getCurrentTimeStr4());
		// 获得一个日历对象
		Calendar c = Calendar.getInstance();
		// 得到本月的那一天
		int today = c.get(c.DAY_OF_MONTH);
		view.setNdate(today);
		List daList = new ArrayList();

		for(int i=1;i<=today;i++){
			Map setMap1 = new HashMap();
			setMap1.put("xdate", i);
			daList.add(setMap1);
		}
		view.setDateList(daList);
		
		uc.setAttribute(TmsConstants.VIEWHELP, view);
		request.setAttribute(TmsConstants.VIEWHELP, view);
		return mapping.findForward(TmsConstants.SUCCESS); 
	}

}
